package org.jeecg.modules.wlhy.hydriver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.wlhy.hydriver.entity.HyDriverReport;
import org.jeecg.modules.wlhy.hydriver.mapper.HyDriverReportMapper;
import org.jeecg.modules.wlhy.hydriver.service.IHyDriverReportService;
import org.springframework.stereotype.Service;

/**
 * @Description: hy_driver_report
 * @Author: jeecg-boot
 * @Date:   2022-11-17
 * @Version: V1.0
 */
@Service
public class HyDriverReportServiceImpl extends ServiceImpl<HyDriverReportMapper, HyDriverReport> implements IHyDriverReportService {

    @Override
    public boolean checkUploadStatus(String driverId, int reportPlatformType){

        LambdaQueryWrapper <HyDriverReport> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HyDriverReport::getDriverId,driverId);
        queryWrapper.eq(HyDriverReport::getReportPlatformType,reportPlatformType);
        HyDriverReport hyDriverReport = this.getOne(queryWrapper);
        if (hyDriverReport != null ) {
            if ("1".equals(hyDriverReport.getDriverUploadStatus())) {
                return true;
            }
        }

        return false;
    }

    @Override
    public boolean saveDriverReport(HyDriverReport hyDriverReport){

        HyDriverReport report = this.getOne(new LambdaQueryWrapper<HyDriverReport>()
                .eq(HyDriverReport::getDriverId, hyDriverReport.getDriverId())
                .eq(HyDriverReport::getReportPlatformType, hyDriverReport.getReportPlatformType())
                .eq(HyDriverReport::getCompanyId, hyDriverReport.getCompanyId()));

        if (null != report) {
            hyDriverReport.setId(report.getId());
            return this.updateById(hyDriverReport);
        }

        return this.save(hyDriverReport);
    }

    @Override
    public boolean checkUploadStatus(String driverId, String companyId, int reportPlatformType) {
        LambdaQueryWrapper <HyDriverReport> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HyDriverReport::getDriverId, driverId);
        queryWrapper.eq(HyDriverReport::getReportPlatformType, reportPlatformType);
        queryWrapper.eq(HyDriverReport::getCompanyId, companyId);
        HyDriverReport hyDriverReport = this.getOne(queryWrapper);
        if (hyDriverReport != null ) {
            if ("1".equals(hyDriverReport.getDriverUploadStatus())) {
                return true;
            }
        }

        return false;
    }
}
